<?php
require_once 'Zend/Controller/Action.php';
class Administrator_ScoreController extends Zend_Controller_Action
{
    public function init()
    {
		$member = new CMember();
        $memberArray = $member->getUserDetails(array('uid' => $_COOKIE[COOKIE_PRE.'uid']));
    	if($_COOKIE[COOKIE_PRE.'uid']=='1'){
				
		} else {
        	$strarray = explode(",", $memberArray[0]['menuflag']);
			if (!in_array('15', $strarray)) {
        		exit('no priviage');
        	}
		}		
    }

    public function preDispatch()
    {
        $this->getHelper ('layout')->setLayout('framelayout');
        $this->view->addHelperPath(MY_ROOT.'/vhelpers');
        Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');
        $member=new CMember();
        if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName()))
        {
            $this->_redirect(MY_URL.'/administrator-auth-login');
            return false;
        }
        return true;
    }
    
    public function indexAction()
    {
    	$score = new CScore();
    	$result = $score->getTotal();
    	$this->view->result = $result;
    }
    
    public function registerscoreAction()
    {
    	$config = new CConfig();
    	if ($this->getRequest()->isPost()) {
    		$score = intval($this->getRequest()->getParam('score'));
    		$statu = intval($this->getRequest()->getParam('statu'));
    		if ($config->editConfig('REGISTER_SCORE', array('data'=>$score . '|' . $statu))) {
    			$this->getHelper('viewRenderer')->setNoRender();
    			$this->view->showMsg('修改成功', '/administrator-score-registerscore');
    		}
    	}
    	$score = $config->getByName('REGISTER_SCORE');
    	if (!$score) {
    		$config->insert(array('name'=>'REGISTER_SCORE', 'data'=>''));
    		$score = $config->getByName('REGISTER_SCORE');
    	}
    	$scoreArr = explode('|', $score->data);
    	$this->view->score = $scoreArr[0];
    	$this->view->statu = $scoreArr[1];
    }
    
    public function orderscoreAction()
    {
    	$config = new CConfig();
    	if ($this->getRequest()->isPost()) {
    		$score = intval($this->getRequest()->getParam('score'));
    		$statu = intval($this->getRequest()->getParam('statu'));
    		$orderDollar = intval($this->getRequest()->getParam('order_dollar'));
    		$config->editConfig('ORDER_DOLLAR', array('data'=>$orderDollar));
    		if ($config->editConfig('ORDER_SCORE', array('data'=>$score . '|' . $statu))) {
    			$this->getHelper('viewRenderer')->setNoRender();
    			$this->view->showMsg('修改成功', '/administrator-score-orderscore');
    		}
    	}
    	$score = $config->getByName('ORDER_SCORE');
    	$orderDollar = $config->getByName('ORDER_DOLLAR');
    	if (!$orderDollar) {
    		$config->insert(array('name'=>'ORDER_DOLLAR', 'data'=>'10'));
    		$orderDollar = $config->getByName('ORDER_DOLLAR');
    	}
    	if (!$score) {
    		$config->insert(array('name'=>'ORDER_SCORE', 'data'=>''));
    		$score = $config->getByName('ORDER_SCORE');
    	}
    	$scoreArr = explode('|', $score->data);
    	$this->view->score = $scoreArr[0];
    	$this->view->statu = $scoreArr[1];
    	$this->view->orderDollar = $orderDollar->data;
    }
    
    public function couponAction()
    {
    	$config = new CConfig();
    	if ($this->getRequest()->isPost()) {
    		$dollar = $this->getRequest()->getParam('dollar');    		
    		if ($config->editConfig('COUPON_DOLLAR', array('data'=>$dollar))) {
    			$this->getHelper('viewRenderer')->setNoRender();
    			$this->view->showMsg('修改成功', '/administrator-score-coupon');
    		}
    	}
    	$dollar = $config->getByName('COUPON_DOLLAR');
    	if (!$dollar) {
    		$config->insert(array('name'=>'COUPON_DOLLAR', 'data'=>'10'));
    		$dollar = $config->getByName('COUPON_DOLLAR');
    	}
    	
    	$this->view->dollar = $dollar->data;
    }
    
    public function memberAction()
    {
    	$config = new CConfig();
    	if ($this->getRequest()->isPost()) {
    		$dollar = $this->getRequest()->getParam('dollar');    		
    		if ($config->editConfig('MEMBER_DOLLAR', array('data'=>$dollar))) {
    			$this->getHelper('viewRenderer')->setNoRender();
    			$this->view->showMsg('修改成功', '/administrator-score-member');
    		}
    	}
    	$dollar = $config->getByName('MEMBER_DOLLAR');
    	if (!$dollar) {
    		$config->insert(array('name'=>'MEMBER_DOLLAR', 'data'=>'10'));
    		$dollar = $config->getByName('MEMBER_DOLLAR');
    	}
    	
    	$this->view->dollar = $dollar->data;
    }
}